﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;

namespace AGrandVenture
{
    public class Stat
    {
        private string name;
        private string abbreviation;
        private string description;

        
        private short statValue;
        private List<Modifier> modifiers;


        public const short MaxStatValue = 100; //set range for stat value;

        public Stat()
        {
        }

        public Stat(string name)
        {
            this.name = name;
        }

        public string Name
        {
            get { return name; }
            set { if (!string.IsNullOrEmpty(value)) name = value; }
        }

        public string Abbreviation
        {
            get { return abbreviation; }
            set { if (!string.IsNullOrEmpty(value)) abbreviation = value; }
        }

        public string Description
        {
            get { return description;}
            set { if (!string.IsNullOrEmpty(value)) description = value;}
        }

        [ContentSerializerIgnore]
        public List<Modifier> Modifiers
        {
            get { return modifiers; }
            set { modifiers = value; }
        }

        [ContentSerializerIgnore]
        public short BaseValue
        {
            get { return statValue; }
            set { statValue = value; }
        }

        public short CurrentValue
        {
            get
            {
                short val = statValue;

                if (modifiers != null)
                {
                    foreach (Modifier modifier in modifiers)
                        val += modifier.Amount;
                }

                return val;
            }
        }

        public void IncreaseValue(short val)
        {
            statValue += val;

            if (statValue > Stat.MaxStatValue)
                statValue = Stat.MaxStatValue;
        }

        public void DecreaseValue(short val)
        {
            statValue -= val;

            if (statValue < 1)
                statValue = 1;
        }

        public void AddModifier(Modifier modifier)
        {
            if (modifiers == null)
                modifiers = new List<Modifier>();

            modifiers.Add(modifier);
        }

        public void Update(float time)
        {
            if (modifiers == null)
                return;

            Modifier modifier;

            for (int i = modifiers.Count; i >= 0; i--)
            {
                modifier = modifiers[i];
                modifier.ElapsedTime += time;

                if ((int)modifier.ElapsedTime >= modifier.Duration)
                    modifiers.Remove(modifier);
                else
                    modifiers[i] = modifier;
            }

			}



        

    }
}
